#include "response.hpp"
#include "itoa.hpp"

resp::resp(int sockfd, char *name, int size)
{
	fd = sockfd;
	file_name = name;
	file_size = size;

	char *ptr = ::itoa(size,10);
	QString str = file_name;
        str += " - ";
	str += ptr;
	str += " bytes";

	dialog = new QWidget;
	accept = new QPushButton(tr("Accept"));
	reject = new QPushButton(tr("Reject"));
	new_file_name = new QLineEdit;
	info = new QLabel(str);
	info->setWordWrap(true);
	info->setAlignment(Qt::AlignCenter);

	response_buttons =  new QHBoxLayout;
	response_buttons->addWidget(accept);
	response_buttons->addWidget(reject);

	response=  new QVBoxLayout;
	response->addWidget(info);
	response->addLayout(response_buttons);
	response->addWidget(new_file_name);

	dialog->setLayout(response);
	dialog->show();

	connect(accept, SIGNAL(clicked()), this, SLOT(e_accept_file()));
	connect(accept, SIGNAL(clicked()), dialog, SLOT(close()));
	connect(reject, SIGNAL(clicked()), dialog, SLOT(close()));
}

void resp::e_accept_file()
{
	emit accept_file(fd, (char*)((new_file_name->text()).toStdString()).c_str(),
		       	file_size);
}
